package org.feiye.studyday19.list;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class HashSet_NewsManger {

	public static void main(String[] args) {
		// 集合存储多条新闻标题
		NewsTitle title1 = new NewsTitle(1, "阿尔法狗大战李世石1", "admin1");
		NewsTitle title2 = new NewsTitle(2, "阿尔法狗大战李世石2", "admin2");
		NewsTitle title3 = new NewsTitle(3, "阿尔法狗大战李世石3", "admin3");
		NewsTitle title4 = new NewsTitle(4, "阿尔法狗大战李世石4", "admin4");
		NewsTitle title5 = new NewsTitle(5, "阿尔法狗大战李世石5", "admin5");
		NewsTitle title6 = new NewsTitle(6, "阿尔法狗大战李世石6", "admin6");

		Set set = new HashSet();
		set.add(title1);
		set.add(title2);
		set.add(title3);
		set.add(title4);
		set.add(title5);
		set.add(title6);

		System.out.println(set.size());
		// foreach遍历
		for (Object object : set) {
			NewsTitle title = (NewsTitle) object;
			System.out.println(title.getTitle());
		}
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
		// 迭代器遍历
		Iterator iterator = set.iterator();// 第一步：拿到迭代器iterator
		while (iterator.hasNext()) {// 第二步： 使用迭代器迭代集合元素
			NewsTitle title = (NewsTitle) iterator.next();
			System.out.println(title.getTitle());
		}

	}

}
